﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using TestApp.Flowchart.Model;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Data;
using Newtonsoft.Json;
using System.Windows.Media;

namespace TestApp.Flowchart
{
    [JsonObject(MemberSerialization.OptIn)]
    public class FlowNode : INotifyPropertyChanged
    {
        private string _guid;
        [JsonProperty]
        public string Guid
        {
            get { return _guid; }
            set
            {
                _guid = value;
                OnPropertyChanged("Guid");
            }
        }

        private int _y;
        [JsonProperty]
        public int Y
        {
            get { return _y; }
            set
            {
                _y = value;
                OnPropertyChanged("Y");
            }
        }

        private int _x;
        [JsonProperty]
        public int X
        {
            get { return _x; }
            set
            {
                _x = value;
                OnPropertyChanged("X");
            }
        }

        private int _height;
        [JsonProperty]
        public int Height
        {
            get { return _height; }
            set
            {
                _height = value;
                OnPropertyChanged("Height");
            }
        }

        private int _width;
        [JsonProperty]
        public int Width
        {
            get { return _width; }
            set
            {
                _width = value;
                OnPropertyChanged("Width");
            }
        }

        private int _level;
        [JsonProperty]
        public int Level
        {
            get { return _level; }
            set
            {
                _level = value;
                OnPropertyChanged("Level");
            }
        }

        private string _text;
        [JsonProperty]
        public string Text
        {
            get { return _text; }
            set
            {
                _text = value;
                OnPropertyChanged("Text");
            }
        }
        
        [JsonProperty]
        public string FullName { get; set; }

        public FlowNode(){ }

        public virtual FrameworkElement CreateContent()
        {
            var tb = new TextBlock()
            {
                TextAlignment = TextAlignment.Left,
                Height = 20,
                Text = this.Text,
            };

            return tb;
        }

        IEnumerable<PortKinds> GetPorts()
		{
            yield return PortKinds.Top;
            yield return PortKinds.Bottom;
            yield return PortKinds.Left;
            yield return PortKinds.Right;
        }
        
        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

		protected void OnPropertyChanged(string name)
		{
			if (PropertyChanged != null)
				PropertyChanged(this, new PropertyChangedEventArgs(name));
		}

        #endregion        
    }
}
